package com.fang.algorithm.sort.selection;

import java.util.Arrays;

/**
 * @author fanglingxiao
 * @version 1.0
 * @description 给你一个整数数组 nums，请你将该数组升序排列
 * 输入：nums = [5,1,1,2,0,0]
 * 输出：[0,0,1,1,2,5]
 * @date 2022/1/5 3:22 下午
 **/
public class Test03_Example {
    public static void main(String[] args) {
        int[] arr = new int[]{5, 1, 1, 2, 0, 0};
        ascSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    private static void ascSort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[i] > arr[j]) {
                    arrSwap(arr, i, j);
                }
            }
        }
    }

    private static void arrSwap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
